package com.lv.service.adapter

import android.graphics.Color
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lv.common.bean.CommonSelectedBean
import com.lv.common.imp.OnPositionTListener
import com.lv.common.ktx.LoadSrc
import com.lv.service.R

/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class RvTabColorAdapter(
    private val datas: MutableList<CommonSelectedBean>,
    layout: Int = R.layout.item_tab_color,
    private val showColor: Int = Color.parseColor("#ff4242"),
    private val disColor: Int = Color.parseColor("#999999")
) :
    BaseQuickAdapter<CommonSelectedBean, BaseViewHolder>
        (layout, datas) {

    override fun convert(
        holder: BaseViewHolder,
        item: CommonSelectedBean,
        payloads: List<Any>
    ) {
        super.convert(holder, item, payloads)
        val tvName = holder.getView<TextView>(R.id.tv_name)
        tvName.setTextColor(
            if (item.selected) showColor else disColor
        )

        tvName.paint.isFakeBoldText = item.selected
    }

    override fun convert(holder: BaseViewHolder, item: CommonSelectedBean) {
        val tvName = holder.getView<TextView>(R.id.tv_name)
        val mIvImage = holder.getView<ImageView>(R.id.iv_image)
        val clParent = holder.getView<ConstraintLayout>(R.id.cl_parent)

        val layoutPosition = holder.layoutPosition
        tvName.text = item.name
        tvName.setTextColor(
            if (item.selected) showColor else disColor
        )
        if (layoutPosition == 0) {
            mIvImage.visibility = View.VISIBLE
            mIvImage.LoadSrc("https://suyiyong.oss-cn-hangzhou.aliyuncs.com/wx/lhy/icon_hot%403x1691549817760.png")
        } else {
            mIvImage.visibility = View.GONE
        }
        tvName.paint.isFakeBoldText = item.selected
        clParent.setOnClickListener {
            onViewClickListener?.onClick(layoutPosition, item)
        }
    }

    var onViewClickListener: OnPositionTListener<CommonSelectedBean>? = null


}